//
//  ReweetedStatusView.swift
//  sina
//
//  Created by DXapple on 15/11/18.
//  Copyright © 2015年 sqlite. All rights reserved.
//

import UIKit
import SnapKit
class ReweetedStatusView: UIView {
    var bottomConstraints: Constraint?

    //数据模型
    var retweetedStatus: Status? {
        
        didSet {
            retweetedLabel.text = retweetedStatus?.text
            
            //判断图片有没有 更新约束
            self.bottomConstraints?.uninstall()

            if let picurls = retweetedStatus?.imageURLs where  picurls.count > 0 {
                pictureView.hidden = false

                pictureView.imageURLs = picurls
                self.snp_updateConstraints(closure: { (make) -> Void in
                    self.bottomConstraints =  make.bottom.equalTo(pictureView.snp_bottom).offset(StatusCellMargin).constraint
                })
            } else {
                pictureView.hidden = true
                self.snp_updateConstraints(closure: { (make) -> Void in
                    self.bottomConstraints =  make.bottom.equalTo(retweetedLabel.snp_bottom).offset(StatusCellMargin).constraint
                })
            }
        }
        
    }
    
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor(white: 0.95, alpha: 1)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
   
    
    private func setupUI() {
    
    addSubview(retweetedLabel)
        addSubview(pictureView)
        
        
        //
        retweetedLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(snp_top).offset(StatusCellMargin)
            make.left.equalTo(snp_left).offset(StatusCellMargin)
        }
    
        pictureView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(retweetedLabel.snp_bottom).offset(StatusCellMargin)
            
            make.left.equalTo(retweetedLabel.snp_left)

        }
    self.snp_makeConstraints { (make) -> Void in
      self.bottomConstraints =  make.bottom.equalTo(pictureView.snp_bottom).offset(StatusCellMargin).constraint
        }
    
    
    
    
    }
    
    
    
    
    
    
    
    

    
    
    private lazy var
    retweetedLabel: UILabel = UILabel(title: "我是转发微博", size: 14, color: UIColor.darkGrayColor(), margin: StatusCellMargin)
    private lazy var pictureView: StatusPictureView = StatusPictureView()
    

    
}
